home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
CLEARC11.ARJ
/
SAMPLE.C
< prev
Wrap
Text File
|
1992-05-15
|
2KB
|
75 lines
#include <stdio.h>
#include <bios.h>
main(int argc, char **argv)
/* This is a C program for testing ClearC V1.1
* The program simply writes a..y diagonally on the screen 6 times
*/
{
void display(int m,char *s);
int m;
char str[27] = "abcdefghijklmnopqrstuvwxyz";// this is at test
// loop invariant P0 == 0<=m<3 and alphabet written m*2 times thus far
m = 0; // P0 true
clrscrn();
while (m != 3)
{
display(m,str); /* call display for writing str */
m++; // add 1 to m => P0 true
} // finished with loop
}
void display(int m,char *s)
/* Pre-cond : 0<=m<3 && s = string of alphabet
* Post-cond: string s written diagonally twice
*/
{
int r, c;
char *ch;
// demonstrate "if" constructs
if (m == 0) // check value of m
c = 0;
else if (m == 1)
c = 10;
else
c = 20; /* c = 0, 10 or 20 depending on m */
// demonstrates "for" constructs
ch = s;
for (r = 0; r != 25; r++)
{
poscurs(r,c++);
printf("%c",*ch++); /* keep looping until r=25 */
}
// another demonstration of "if" construct
if (m == 0)
{
c = 5;
}
else if (m == 1) {
c = 15;
}
else {
c = 25;
} /* c = 5, 15 or 25 depending on m */
// demonstrates "while" construct
r = 0;
ch = s;
while (r != 25) { /* loop until r=25 */
poscurs(r++,c++); /* position cursor for display */
printf("%c",*ch++); /* print character */
}
}